package com.lzh.seatrend.config.es;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

/**
 * @Classname ElasticSearchConfig
 * @Description TODO
 * @Date 2021/11/8 15:24
 * @Created by liuzihao
 */
public class ElasticSearchConfig {


    @Bean
    RestHighLevelClient elasticsearchClient(){
        ClientConfiguration configuration = ClientConfiguration.builder()
                .connectedTo("127.0.0.7:9300") //集群地址，默认值HttpHeaders 或 启用SSL
//                .withConnectTimeout(Duration.ofSeconds(5)) // 设置连接超时.默认10s
//                .withSocketTimeout(Duration.ofSeconds(3)) // 设置套接字超时，默认5s
//                .withDefaultHeaders() //设置标题
//                .withBasicAuth() //添加基本身份验证
                .build();
        RestHighLevelClient client = RestClients.create(configuration).rest();
        return client;
    }
}
